package com.qf.fmall.orders.controller;

import com.qf.fmall.orders.entity.Orders;
import com.qf.fmall.orders.service.IOrdersService;
import com.qf.fmall.utils.WxPayUtils;
import com.qf.fmall.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 订单  前端控制器
 * </p>
 *
 * @author dongjl
 * @since 2024-01-18
 */
@CrossOrigin
@RestController
@RequestMapping("/order")
public class OrdersController {

    @Autowired
    private IOrdersService ordersService;

    @GetMapping("/status/{orderId}")
    public ResultVo status(@PathVariable("orderId") String orderId ){
        String orderStatus = WxPayUtils.getOrderStatus(orderId);
        if (orderStatus.equals("SUCCESS")){
            return new ResultVo(10000, "success", 2);
        }else {
            return new ResultVo(10000, "success", -1);
        }
    }

    @PostMapping("/add")
    public ResultVo add(@RequestParam("cids") List<String> cids, @RequestBody Orders orders) throws ParseException {

        HashMap<String, Object> data = ordersService.add(cids, orders);
        return new ResultVo(10000, "success", data);
    }

}
